package persistence;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import persistence.connection.PoolConnection;

import model.Sede;

public class SedePersistsAdm {

	private static SedePersistsAdm sedePersistsAdm;
	
	private SedePersistsAdm(){}
	
	public static SedePersistsAdm getInstance(){
		
		if (sedePersistsAdm == null)
			sedePersistsAdm = new SedePersistsAdm();
		
		return sedePersistsAdm;
	}
	
	public ArrayList<Sede> select(){		
		Connection con = PoolConnection.getPoolConnection().getConnection();
		String sentencia = "select * from dbLiforBasquet.dbo.Sedes";
		ArrayList<Sede> sedes = new ArrayList<Sede>();
		
		try {			
			PreparedStatement ps = con.prepareStatement(sentencia);
			ResultSet rs = ps.executeQuery();
			
			while (rs.next()){
				Sede sede = new Sede();
				sede.setId(rs.getInt("id"));
				sede.setDescripcion(rs.getString("descripcion"));
				sede.setDireccion(rs.getString("direccion"));
				sede.setTelefono(rs.getString("telefono"));
				sede.setEstado(rs.getString("estado"));
				sede.setPartidosPorDia(rs.getInt("partidosPorDia"));
				//s.setTurnos(obtenerTurnos());	
				
				sedes.add(sede);
			}		
		} catch (Exception e) {		
			System.out.println("Error al obtener sedes: " + e.getMessage());
		}	
		
		PoolConnection.getPoolConnection().realeaseConnection(con);
		return sedes;
	}
}
